import Vue from 'vue'
import VueRouter from 'vue-router'
import index from '../views/index.vue'
import company from '../components/company.vue'
import contact from '../components/contact.vue'
import home from '../components/home.vue'
import news from '../components/news.vue'
import product from '../components/product.vue'
// 解决重复点击菜单加载相同URL报错的问题
const originalPush = VueRouter.prototype.push
VueRouter.prototype.push = function push (location) {
  return originalPush.call(this, location).catch(err => err)
}
Vue.use(VueRouter)

const routes = [
  {
    path: '/',
    name: 'index',
    component: index,
    redirect: '/home',
    children: [
      {
        path: '/home',
        name: 'home',
        component: home
      },
      {
        path: '/company',
        name: 'company',
        component: company
      },
      {
        path: '/contact',
        name: 'contact',
        component: contact
      },
      {
        path: '/news',
        name: 'news',
        component: news
      },
      {
        path: '/product',
        name: 'product',
        component: product
      }
    ]
  }
]

const router = new VueRouter({
  // mode: 'history',
  routes
})

export default router
